﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Aim2.Weapon {
    public abstract class Weapon : AnimatedObject {
        public Player Owner { get; set; }
        protected string fireSoundEffect = String.Empty; 

        protected float timeToNextFire = 0.01f;
        protected float fireDelay = 0f;

        protected Weapon(Player owner) {
            this.Owner = owner;
        }

        public override Side Side() {
            return Aim2.Side.Harmless;
        }

        public void UpdateWeapon(float elapsedTime) {
            if (timeToNextFire > 0f) {
                timeToNextFire = MathHelper.Max(timeToNextFire - elapsedTime, 0f);
            }
        }

        public virtual void Fire(Vector2 direction, Side side) {
            if (timeToNextFire > 0f) {
                 return;
            }

            timeToNextFire = fireDelay;

            CreateProjectiles(direction, side);

            if (String.IsNullOrEmpty(fireSoundEffect) == false) {
                AudioManager.PlaySoundEffect(fireSoundEffect);
            }
        }

        protected abstract void CreateProjectiles(Vector2 direction, Side side);

        public override void TakeDamage(float f) {
            //NOP
        }
    }
}
